package lyttest.controller;


import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import lyttest.entity.dto.FileDTO;
import lyttest.entity.dto.UserDTO;
import lyttest.service.GetInfoService;
import lyttest.service.UserService;
import lyttest.uils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/v3")
public class TemplateUDController {
    @Autowired
    private GetInfoService getInfoService;
    @PostMapping("/download")
    public ResponseEntity<String> downloadFile(@RequestBody UserDTO userDTO) {
        try {
            log.info("下载app文件Request:{} ", JSON.toJSONString(userDTO));
            return getInfoService.download(userDTO);
        } catch (Exception e) {
            log.error("下载app文件,输入参数: ", JSON.toJSONString(userDTO), e);
            return ResponseEntity.notFound().build();
        }
    }

    @PostMapping("/upload")
    public Response<String> uploadloadFile(@ModelAttribute  UserDTO userDTO, @RequestParam("file") MultipartFile multipartFile) {
        try {
            log.info("上传本地文件Request:{} ", JSON.toJSONString(userDTO));
            return getInfoService.upload(userDTO,multipartFile);
        } catch (Exception e) {
            log.error("上传本地文件,输入参数: ", JSON.toJSONString(userDTO), e);
            return Response.createError("文件上传失败");
        }
    }

}